package com.lmx.repoDomain.repository;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.lmx.common.constants.CommonConstants;
import com.lmx.persistence.service.SchemeService;
import com.lmx.repoDomain.tmodel.Scheme;

import io.katharsis.repository.annotations.JsonApiResourceRepository;
import io.katharsis.repository.annotations.JsonApiSave;

@JsonApiResourceRepository(Scheme.class)
@Component
public class SchemeRespository extends BaseRepository<Scheme> {

	@PostConstruct
	public void init() {
		dslJpaService.setEntityClass(Scheme.class);
	}

	@Autowired
	SchemeService service;

	@Override
	@JsonApiSave
	public Scheme save(final Scheme entity) {
		if (entity.getId() == null) {
			this.service.checkRepeat(entity);
		}
		if (CommonConstants.DEL_STATUS_YES_1.equals(entity.getDelStatus())) {
			this.service.checkDelete(entity);
		}
		return super.save(entity);
	}
}
